<template>
	<view class="home">
		<view class="content" v-if="!isData">
			<view class="date-wrap">
				<view class="time">考勤期间:{{ date }}</view>
				<view class="prograss" @click="checkPrograss">审核进度</view>
			</view>
			<view v-if="rovalListData.length == '0'" class="data-tip">当前没有任何数据</view>
			<view v-for="(item, index) in rovalListData" class="attend-card" :key="index">
				<attend-examine-card
					:leaveNum="item.count"
					:attendeData="item"
					@clickDetail="clickDetail(item)"
					@adopt="adopt(item, index)"
					@exit="exit(item, index)"
				></attend-examine-card>
			</view>
		</view>
		<view class="btn" v-if="isExamine=='0'">
			<assignCharacter  billtype="HAAP" :formPk="pk"></assignCharacter>
			<view @click="exit()" class="exit">考勤驳回</view>
			<view @click="adopt()" class="adopt">考勤通过</view>
		</view>
		<sendNews ref="sendNews" @confirm='confirm' :status ='examineStatus'></sendNews>
		<!-- 未审核的btn -->
		<view  v-if="showBtn">
			<view class="btn" v-if="isExamine=='1'">
				<view @click="exitExamine()" class="exit">取消审批</view>
			</view>
		</view>
		<!-- 已审核的btn -->
		<!-- <view class="remineStatus">
			<view>已批准</view>
			<view>已驳回</view>
		</view> -->
	</view>
</template>

<script>
import service from '../../common/service/new_file.js';
import apiData from '../../common/utils/apiData.js';
export default {
	data() {
		return {
			isData: true,
			isExamine:'',
			test: ['1', '1'],
			rovalListData: [],
			month: '',
			date: '',
			teamproperty: '',
			showBtn:'',
			pk:'',
			examineStatus:'',//1为通过，0为未通过
		};
	},
	methods: {
		checkPrograss() {
			uni.navigateTo({
				url: './attendacePrograss?pk=' + this.rovalListData[0].pk_attendreport+'&billtype=HAAP'
			});
		},
		confirm(value){
			let _this = this;
			if(this.examineStatus==1){
				let data = apiData.setExamineData('HAAP', true, this.rovalListData[0].pk_attendreport,value);
				service.common(data, {
					success: function(res) {
						// alert('返回'+JSON.stringify(res.data))
						uni.showToast({
							title: '已通过',
						});
						uni.navigateTo({
							url:'./remineThing'
						})
					},
					fail: function(err) {
						console.log(err);
					}
				});
			}else if(this.examineStatus==0){
				let data = apiData.setExamineData('HAAP', false, this.rovalListData[0].pk_attendreport,value);
				service.common(data, {
						success: function(res) {
							// alert('返回' + JSON.stringify(res.data));
								uni.showToast({
									title: '已驳回'
								});
								uni.navigateTo({
									url:'./remineThing'
								})
						},
						fail:(err)=>{
							
						}
					});
				} 
		},
		adopt() {
			this.examineStatus = 1
			this.$refs.sendNews.show()
		},
		exitExamine(){
			let _this = this
			let data = apiData.setExitExamineData(this.pk,'HAAP')//FN(billtype, isAdopt,pk)
			service.common(data, {
				success: function(res) {
						uni.showToast({
							title:'已取消审批'
						})
						uni.navigateTo({
							url:'./remineThing'
						})
					// _this.getLeaveList()
				},
				fail:function(err){
				},
				all:function(all){
				}
			})
		},
		exit() {
			this.examineStatus = 0
			this.$refs.sendNews.show()
			//唤起意见框
		},//驳回审批

		clickDetail(item) {
			uni.navigateTo({
				url: './attedanceDetail?item=' + JSON.stringify(item) + '&month=' + this.month + 
					'&teamproperty=' + this.teamproperty+'&year='+this.date
			});
		},
		tabClick(index) {
			this.activeIndex = index ? index : '0';
			if (this.activeIndex == 0) {
				this.isData = this.test.length == 0 ? true : false;
			} else if (this.activeIndex == 1) {
				this.isData = this.rovalListData.length == 0 ? true : false;
			}
		}
	},
	onLoad(option) {
		
		this.isExamine = option.isExamine
		this.showBtn = option.showBtn?false:true
		let newMonthNum = parseInt(option.month) - 1;
		let month = new Date().setMonth(newMonthNum, 1);
		let timeCode = new Date(month);
		let obj = JSON.parse(option.item)
		this.date = obj.hvo.pk_period.yearmth;
		// this.date = 2010+'年人力资源部'+(8 + 1) + '月考勤';
		
		this.month = option.month;
		this.teamproperty = obj.hvo.teamproperty;
		this.pk = obj.hvo.pk_attendreport
		this.rovalListData = obj.bvos;
	},
	onReady() {
		this.tabClick();
	}
};
</script>

<style scoped lang="scss">
.content {
	padding: 0 0 100rpx 0;
}
.home {
	position: relative;
}
.btn {
	background: #faf9fa;
	align-items: center;
	width: 100vw;
	height: 100rpx;
	margin: 0 auto;
	display: flex;
	position: fixed;
	bottom: 0;
	.exit {
		color: #fe131a;
		height: 70%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		text-align: center;
	}
	.adopt {
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		text-align: center;
		height: 70%;
		border-left: 2rpx solid #e3e3e3;
		color: #36aa6a;
	}
}
.date-wrap {
	margin-top: 20rpx;
	width: 100vw;
	display: flex;
	justify-content: space-between;
	.time {
		font-size: 28rpx;
		height: 100rpx;
		padding-top: 20rpx;
		padding: 0 30rpx;
	}
	.prograss {
		width: 150rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #007aff;
		text-align: center;
	}
}
.data-tip {
	text-align: center;
	color: #949494;
	font-size: 28rpx;
}
.attend-card {
	margin: 30rpx 0;
}
</style>
